﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;

namespace devtm.Aop.Extensions
{
    public static class GenericInstanceTypeExt
    {   
        
        
        public static GenericInstanceType GetClosedGenericInstanceType(
            this GenericInstanceType @interface,
            GenericInstanceType template,
            TypeDefinition target)
        {


            var interfaceDefinition = @interface.Resolve();
            var interfaceRefInTarget = target.Module.Import(interfaceDefinition);
            var interfaceDefInTarget = new GenericInstanceType(interfaceRefInTarget);


            foreach (var genericArgument in template.GenericArguments)            
                interfaceDefInTarget.GenericArguments.Add(genericArgument);
            

            return interfaceDefInTarget;

        }




 
    }
}
